<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 300px;
            height: 400px;
            border: 3px solid;
            margin: 100px auto;
            padding: 0 20px;
        }

        input {
            height: 30px;
            border: 1px solid #eee;
        }

        .d1 {
            margin-top: 20px;
            margin-left: 50px;
            height: 40px;
        }

        .d2 .hang {
            display: flex;
            justify-content: space-between;
            height: 60px;
            background-color: antiquewhite;
            line-height: 60px;
            margin-top: 10px;
        }

        .hang input {
            margin-top: 16px;
        }

        .kong {
            color: red;
            text-align: center;
        }
        .d2 .active{
            background-color: greenyellow;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="d1">
            <input type="text" placeholder="输入任务名称" v-model="zhi">
            <button @click="add">提交</button>
        </div>
        <div class="d2">
            <div :class="{hang:true,active:item.status}" v-for="(item,index) in list" :key="index">
                <input type="checkbox" @click="tai(item)">
                <div class="name">{{item.name}}</div>
                <div class="caoz">删除</div>
            </div>
            <div class="kong" v-show="list.length==0">任务列表空空如也！！！</div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '.box',
        data: {
            zhi: '',
            list: []
        },
        methods: {
            add() {
                if(this.zhi){
                    var obj={id:this.list.length+1,name:this.zhi,status:false}
                    this.list.push(obj)
                    this.zhi=''
                }
            },
            tai(item){
                item.status=!item.status
            }
        }

    })
</script>